package forum.server.domain;

import java.util.Date;

import forum.server.exceptions.UnauthorizedOpException;
import forum.server.persistence.old.UserType;
/**
 * The class extends LoggedInUser and represents a moderator who in addition
 * to the registered user functionality has additional functionality such as 
 * modifing or deleting any post in his forums.
 * @author Alon Furman
 */

public class Moderator extends LoggedInUser {

    /**
     * Default contructor for the xml.
     */
    public Moderator(){
    	super();
    }
        
    /**
     * Constructor used to create new moderator given his personal information.
     * @param username - Moderator's username.
     * @param password - Moderator's password.
     * @param firstName - Moderator's first name.
     * @param lastName - Moderator's last name.
     * @param gender - Moderator's gender.
     * @param city - Moderator's city name.
     * @param birthday - Moderator's birthday date.
     */
    public Moderator(String username, String password, String firstName,
            String lastName, String email, Gender gender, String city, Date birthday) {
        super(username, password, firstName, lastName, email, gender, city, birthday);
    }

    /**
     * Constructor which creates a moderator from registered user with the
     * personal details of  a regular user recieved as parameter.
     * Used to support the promote moderator functionality in Admin class.
     * @param ru - Registered user for promotion.
     */
    public Moderator(LoggedInUser ru){
        this(ru.getUsername(),ru.getPassword(),ru.getFirstName(),ru.getLastName(),
                ru.getEmail(), ru.getGender(),ru.getCity(),ru.getBirthday());
    }

     /**
     * Constructor which creates a new moderator with the minimal
     * required information: username and password, without personal details.
     * @param username - Moderator's username.
     * @param password - Moderator's password.
     */
    public Moderator(String username, String password){
        super(username,password);
    }

   /**
     * Modifies any existing post with a new post content.
     * @param post - The post to be modified.
     * @param aNewContent - New content for the post.
     * @return The post after modification.
     */
    @Override
    public Post modifyPost(Post post, PostContent aNewContent){
    	post.setContent(aNewContent);
    	return post;	
    }

    /**
     * Deletes a post from the forum.
     * Moderator can delete any post in the forum, therefore no exception is never thrown.
     * @param post - The post to delete.
     * @throws  UnauthorizedOpException - Thrown in case of illegal delete attempt.
     */
    public void deletePost(Post post) throws UnauthorizedOpException {}
    
    /**
     * The function is used to support the promote functionality in any type of user.
     * Due to the fact that only the admin can promote moderators an exception is thrown.
     * @param user - LoggedInUser to promote to moderator.
     * @return - The promoted Moderator.
     * @throws UnauthorizedOpException - thrown in case of a Moderator trying to perform the operation.
     */
    @Override
    public Moderator promoteModerator(LoggedInUser user) throws UnauthorizedOpException{
    	throw new UnauthorizedOpException("Moderators can't promote moderators");
    }
    
    /**
     * The function is used to support the demote functionality in any type of user.
     * Due to the fact that only the admin can demote moderators an exception is thrown.
     * @param moderator - Moderator to demote to LoggedInUser.
     * @return - The demoted LoggedinUser.
     * @throws UnauthorizedOpException - thrown in case of a Moderator trying to perform the operation.
     */
    @Override
    public LoggedInUser demoteModerator(Moderator moderator) throws UnauthorizedOpException{
    	throw new UnauthorizedOpException("Moderators can't demote moderators");
    }
    /**
     * 
     * @return the permission of the user.
     */
    public UserType getPermission(){
    	return UserType.MODERATOR;
    }
}
